package com.steel.yfmall.cloud.assistant.stock.impl;

import com.steel.yfmall.cloud.assistant.dto.para.stock.ParaSteelChannelDepotSkuLimitBean;
import com.steel.yfmall.cloud.assistant.dto.result.stock.ResultSteelChannelDepotSkuLimitBean;
import com.steel.yfmall.cloud.assistant.po.stock.SteelChannelDepotSkuLimitBean;
import com.steel.yfmall.cloud.assistant.po.stock.SteelChannelDepotSkuLimitBeanExample;
import com.steel.yfmall.cloud.assistant.stock.SteelChannelDepotSkuLimitBeanService;
import com.steel.yfmall.cloud.assistant.stock.mapper.SteelChannelDepotSkuLimitBeanMapper;
import com.steel.yfmall.cloud.components.utils.utils.MobileBaseBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jia chang bao
 * @date 2021/2/23 20:51
 */
@Service
@Slf4j
public class SteelChannelDepotSkuLimitBeanServiceImpl implements SteelChannelDepotSkuLimitBeanService {
    /**
     * 批量查询商品挂牌信息 不分页
     *
     * @param paraSteelChannelDepotSkuLimitBean
     * @return 结果集合
     * @author jia chang bao
     */
    @Override
    public List<ResultSteelChannelDepotSkuLimitBean> getSteelChannelDepotSkuBeanOfList(ParaSteelChannelDepotSkuLimitBean paraSteelChannelDepotSkuLimitBean) {
        SteelChannelDepotSkuLimitBeanExample steelChannelDepotSkuLimitBeanExample = checkData(paraSteelChannelDepotSkuLimitBean);
        List<SteelChannelDepotSkuLimitBean> steelChannelDepotSkuLimitBeans = steelChannelDepotSkuLimitBeanMapper.selectByExample(steelChannelDepotSkuLimitBeanExample);
        if (!CollectionUtils.isEmpty(steelChannelDepotSkuLimitBeans)) {
            List<ResultSteelChannelDepotSkuLimitBean> list = new ArrayList<>();
            for (SteelChannelDepotSkuLimitBean steelChannelDepotSkuLimitBean : steelChannelDepotSkuLimitBeans) {
                ResultSteelChannelDepotSkuLimitBean resultSteelChannelDepotSkuLimitBean = new ResultSteelChannelDepotSkuLimitBean();
                MobileBaseBeanUtils.copyAllFields(steelChannelDepotSkuLimitBean, resultSteelChannelDepotSkuLimitBean);
                list.add(resultSteelChannelDepotSkuLimitBean);
            }
            return list;
        }
        return null;
    }

    /**
     * 根据 多个 productSysCodes（商品编码） 批量删除
     *
     * @param paraSteelChannelDepotSkuLimitBean
     * @return true 成功，false 失败
     * @author jia chang bao
     */
    @Override
    public Boolean deleteSteelChannelDepotSkuBeanByList(ParaSteelChannelDepotSkuLimitBean paraSteelChannelDepotSkuLimitBean) {
        SteelChannelDepotSkuLimitBeanExample steelChannelDepotSkuLimitBeanExample = checkData(paraSteelChannelDepotSkuLimitBean);
        int i = steelChannelDepotSkuLimitBeanMapper.deleteByExample(steelChannelDepotSkuLimitBeanExample);
        if (i > 0) {
            return true;
        }
        return false;
    }

    private SteelChannelDepotSkuLimitBeanExample checkData(ParaSteelChannelDepotSkuLimitBean paraSteelChannelDepotSkuLimitBean) {
        SteelChannelDepotSkuLimitBeanExample steelChannelDepotSkuLimitBeanExample = new SteelChannelDepotSkuLimitBeanExample();
        SteelChannelDepotSkuLimitBeanExample.Criteria criteria = steelChannelDepotSkuLimitBeanExample.createCriteria();

        //多个商品编码
        if (!CollectionUtils.isEmpty(paraSteelChannelDepotSkuLimitBean.getProductSysCodes())) {
            criteria.andProductSysCodeIn(paraSteelChannelDepotSkuLimitBean.getProductSysCodes());
        }

        return steelChannelDepotSkuLimitBeanExample;
    }

    @Resource
    private SteelChannelDepotSkuLimitBeanMapper steelChannelDepotSkuLimitBeanMapper;
}
